﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Stock.仓库信息
{
    public partial class Depot : Form
    {
        public Depot()
        {
            InitializeComponent();
        }

        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DepotAddAndEdit DA =new DepotAddAndEdit();
            DA.f = this;
            DA.Show();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DepotAddAndEdit da = new DepotAddAndEdit();
            da.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            da.DName = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            da.Phone = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            da.f = this;
            da.Show();

        }

        public void Depot_Load(object sender, EventArgs e)
        {
            //取消自动列
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select("select * from Depot");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string sql = $"select * from Depot where DName like '%{name}%'";
            //取消自动列
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select(sql);

        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            string sql = "delete from Depot where Id="+Id;
            if (DBH.NoSelect(sql) > 0)
            {
                MessageBox.Show("删除成功！");
                Depot_Load(null, null);
            }
            else
            {
                MessageBox.Show("删除失败！");
            }
        }
    }
}
